package site.wanjiahao.stack;

import java.util.LinkedList;
import java.util.Queue;

public class MyStack {

    private Queue<Integer> inQueue;

    private Queue<Integer> outQueue;


    /**
     * Initialize your data structure here.
     */
    public MyStack() {
        inQueue = new LinkedList<>();
        outQueue = new LinkedList<>();
    }

    /**
     * Push element x onto stack.
     */
    public void push(int x) {
        inQueue.offer(x);
        // 出队列不为空
        Queue<Integer> temp = outQueue;
        outQueue = inQueue;
        inQueue = temp;
        while (!inQueue.isEmpty()) {
            outQueue.offer(inQueue.poll());
        }
    }

    /**
     * Removes the element on top of the stack and returns that element.
     */
    public int pop() {
        return outQueue.poll();
    }

    /**
     * Get the top element.
     */
    public int top() {
        return outQueue.peek();
    }

    /**
     * Returns whether the stack is empty.
     */
    public boolean empty() {
        return outQueue.isEmpty();
    }

}